<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Cashier extends CI_Controller {

	public function index()
	{
		//modell
		$this->load->model('Products_model');
		$data['products_model'] = $this->Products_model;
		$data['selected_category_id'] = -1;
		
		//view
		$this->load->view('head');
		$this->load->view('header', array('activeLink' => "none"));
		//$this->load->view('cart', $data);
		$this->load->view('cashier', $data);
		$this->load->view('footer');
	}
	
	public function order() 
	{
		$this->load->library('cart');
		
	 	$config['protocol'] = 'smtp';
        $config['mail_path'] = 'ssl://smtp.googlemail.com';
        $config['smtp_host'] = 'ssl://smtp.googlemail.com';
        $config['smtp_port'] = 465;
        //$config['smtp_port'] = 25;
        $config['smtp_user'] = 'kornvollis@gmail.com';
        $config['smtp_pass'] = '19861215GmailPower';
		
        $this->load->library('email', $config);
	    $this->email->set_newline("\r\n");
	    $this->email->from('kornvollis@gmail.com', 'ÚJ Megrendelés');
	    $this->email->to('kornvollis@gmail.com');
	    $this->email->subject('Email test bitches');
	   	$this->email->set_mailtype("html");
        
	   	$items = "";
	   	foreach($this->cart->contents() as $item) {
	   		$items .= '<tr><td>'.$item['name'].'</td><td>'.$item['price'].'</td><td>'.$item['qty'].'</td></tr>';
	   	}
	   	
        // message
		$message = '
		<html>
		<head>
		  <title>Megrendelés érkezet a Smaragd web shopból!!!</title>
		</head>
		<body>
		  <p>A megrendelő neve:'. $this->input->post('lastname') .' '. $this->input->post('firstname') .'</p>
		  <p>Telefon száma:'. $this->input->post('phone') .'</p>
		  <p>Email címe:'. $this->input->post('email') .'</p>
		  <p>Címe: '. $this->input->post('address') .'</p>
		  <p>Az alábbi termékeket rendelte:</p>
		  <table>
		    <tr>
		      <th>Termék neve</th><th>Ára</th><th>Darab</th>
		    </tr>'
		    .$items.
		  '</table>
		</body>
		</html>
		';
        
	    $this->email->message($message);

        if($this->email->send())
        {
            $this->load->view('head');
			$this->load->view('header', array('activeLink' => "none"));
			$this->load->view('order_success');
			$this->load->view('footer');
        }else{
            show_error($this->email->print_debugger());
        }
	}
	
}